package com.acwing.partition10;

import java.io.*;
import java.util.Random;

/**
 * @author `RKC`
 * @date 2022/5/4 21:42
 */
public class AC950郁闷的出纳员 {

    private static final int N = 100010, INF = 0x3f3f3f3f;
    private static final Random r = new Random();
    private static Node[] tr = new Node[N];
    private static boolean[] st = new boolean[N];
    private static int n, root, minv, idx = 0, cnt = 0;

    private static StreamTokenizer tokenizer = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
    private static PrintWriter writer = new PrintWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        n = nextInt(); minv = nextInt();
        build();
        for (int i = 0; i < n; i++) {
            char opt = next().charAt(0);
            int x = nextInt();
            if (opt == 'I') {
                if (x < minv) continue;
                root = insert(root, x);
            } else if (opt == 'A') add(root, x);
            else if (opt == 'S') root = sub(root, x);
            else {
                int res = kth(root, x + 1);
                if (res <= 0) res = -1;
                writer.println(res);
            }
        }
        writer.println(cnt);
        writer.flush();
    }

    private static int kth(int p, int k) {
        if (p == 0) return p;
        if (tr[tr[p].l].size >= k) return kth(tr[p].l, k);
        if (tr[tr[p].l].size + tr[p].cnt >= k) return tr[p].key;
        return kth(tr[p].r, k - tr[tr[p].l].size - tr[p].cnt);
    }

    private static int remove(int p, int key) {
        if (p == 0) return 0;
        if (key < tr[p].key) tr[p].r = remove(tr[p].r, key);
        else if (key > tr[p].key) tr[p].l = remove(tr[p].l, key);
        else {
            if (tr[p].l != 0 || tr[p].r != 0) {
                if (tr[p].r == 0 || tr[tr[p].l].rnd > tr[tr[p].r].rnd) {
                    p = zig(p);
                    tr[p].r = remove(tr[p].r, key);
                } else {
                    p = zag(p);
                    tr[p].l = remove(tr[p].l, key);
                }
            } else {
                return 0;
            }
        }
        pushup(p);
        return p;
    }

    private static int insert(int p, int key) {
        if (p == 0) return create(key);
        if (tr[p].key == key) tr[p].cnt++;
        else if (key < tr[p].key) {
            tr[p].r = insert(tr[p].r, key);
            if (tr[tr[p].r].rnd > tr[p].rnd) p = zag(p);
        } else {
            tr[p].l = insert(tr[p].l, key);
            if (tr[tr[p].l].rnd > tr[p].rnd) p = zig(p);
        }
        pushup(p);
        return p;
    }

    private static void add(int p, int k) {
        if (p == 0) return;
        if (!st[p]) {
            if (tr[p].key != INF && tr[p].key != -INF) tr[p].key += k;
            add(tr[p].l, k);
            add(tr[p].r, k);
        }
    }

    private static int sub(int p, int k) {
        if (p == 0 || st[p]) return p;
        if (tr[p].key != INF && tr[p].key != -INF) tr[p].key -= k;
        tr[p].l = sub(tr[p].l, k);
        tr[p].r = sub(tr[p].r, k);
        //如果比最低标准都低，在这个标准的所有人都会退出
        if (tr[p].key < minv && tr[p].key != -INF) {
            cnt += tr[p].cnt;
            //标记已经退出
            st[p] = true;
            p = remove(p, tr[p].key);
        }
        pushup(p);
        return p;
    }

    private static void build() {
        tr[0] = new Node(0);
        root = create(INF);
        tr[root].r = create(-INF);
        pushup(root);
        if (tr[tr[root].r].rnd > tr[root].rnd) root = zag(root);
    }

    private static int zig(int p) {
        int q = tr[p].l;
        tr[p].l = tr[q].r;
        tr[q].r = p;
        pushup(p);
        pushup(q);
        return q;
    }

    private static int zag(int p) {
        int q = tr[p].r;
        tr[p].r = tr[q].l;
        tr[q].l = p;
        pushup(p);
        pushup(q);
        return q;
    }

    private static void pushup(int p) {
        tr[p].size = tr[tr[p].l].size + tr[tr[p].r].size + tr[p].cnt;
    }

    private static int create(int key) {
        tr[++idx] = new Node(key);
        tr[idx].rnd = r.nextInt(N);
        tr[idx].cnt = tr[idx].size = 1;
        return idx;
    }

    private static class Node {
        private int l, r, key, rnd, cnt, size;

        public Node(int key) {
            this.key = key;
        }
    }

    private static int nextInt() throws IOException {
        tokenizer.nextToken();
        return (int) tokenizer.nval;
    }

    private static String next() throws IOException {
        tokenizer.nextToken();
        return tokenizer.sval;
    }
}
